<?php
namespace app\api\controller;
use app\common\controller\Frontend;
use EasyWeChat\Factory;
use think\Log;
use think\Session;
/**
 * 账户中心
 */
class Register extends Frontend{
    
    protected function _initialize(){
        parent::_initialize();
        if($this->auth->isLogin()){
            $url = Session::get('referUrl');
            if($url){
                $this->redirect($url);
            }else{
                $this->redirect('account/index');
            }
            exit();
        }else{
            $wechat = Factory::officialAccount(config('wechat'));
            if(!Session::get('lifeOpenid')){
                $redirect =  $wechat->oauth->scopes(['snsapi_base'])->redirect(url('mpwechat/baseoauth',['skip'=>str_replace('_','_',$this->path)],false,true));
                $this->redirect($redirect);
                exit();
             }
        }
    }

    public function index(){
        
        return $this->view->fetch();
    }
}